<?php
// +----------------------------------------------------------------------
// | yylAdmin 前后分离，简单轻量，免费开源，开箱即用，极简后台管理系统
// +----------------------------------------------------------------------
// | Copyright https://gitee.com/skyselang All rights reserved
// +----------------------------------------------------------------------
// | Gitee: https://gitee.com/skyselang/yylAdmin
// +----------------------------------------------------------------------

namespace {$controller.namespace};

use app\common\BaseController;
use {$validate.namespace}\{$validate.class_name} as {$validate.class_name}Validate;
use {$service.namespace}\{$service.class_name} as {$service.class_name}Service;
use hg\apidoc\annotation as Apidoc;

/**
 * @Apidoc\Title("{$form.controller_title}")
 * @Apidoc\Group("{$form.group}")
 * @Apidoc\Sort("999")
 */
class {$controller.class_name} extends BaseController
{
    /**
     * @Apidoc\Title("{$form.controller_title}列表")
     * @Apidoc\Method("GET")
     * @Apidoc\Param(ref="pagingParam")
     * @Apidoc\Param(ref="sortParam")
     * @Apidoc\Param(ref="searchParam")
     * @Apidoc\Param(ref="dateParam")
     * @Apidoc\Returned(ref="pagingReturn")
     * @Apidoc\Returned("list", ref="{$tables[0].model_path}\{$tables[0].model_name}\listReturn", type="array", desc="{$form.controller_title}列表")
     */
    public function list()
    {
        $where = $this->where(['is_delete', '=', 0], 'id');

        $data = {$service.class_name}Service::list($where, $this->page(), $this->limit(), $this->order());

        return success($data);
    }

    /**
     * @Apidoc\Title("{$form.controller_title}信息")
     * @Apidoc\Method("GET")
     * @Apidoc\Param(ref="{$tables[0].model_path}\{$tables[0].model_name}\id")
     * @Apidoc\Returned(ref="{$tables[0].model_path}\{$tables[0].model_name}\infoReturn")
     */
    public function info()
    {
        $param['id'] = $this->param('id/d', '');

        validate({$validate.class_name}Validate::class)->scene('info')->check($param);

        $data = {$service.class_name}Service::info($param['id']);
        if ($data['is_delete'] == 1) {
            exception('{$form.controller_title}已被删除：' . $param['id']);
        }

        return success($data);
    }

    /**
     * @Apidoc\Title("{$form.controller_title}添加")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="{$tables[0].model_path}\{$tables[0].model_name}\addParam")
     * @Apidoc\Returned(ref="{$tables[0].model_path}\{$tables[0].model_name}\infoReturn")
     */
    public function add()
    {
        $param = $this->param();

        validate({$validate.class_name}Validate::class)->scene('add')->check($param);

        $data = {$service.class_name}Service::add($param);

        return success($data);
    }

    /**
     * @Apidoc\Title("{$form.controller_title}修改")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="{$tables[0].model_path}\{$tables[0].model_name}\editParam")
     */
    public function edit()
    {
        $param = $this->param();

        validate({$validate.class_name}Validate::class)->scene('edit')->check($param);

        $data = {$service.class_name}Service::edit($param['id'], $param);

        return success($data);
    }

    /**
     * @Apidoc\Title("{$form.controller_title}删除")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="idsParam")
     */
    public function dele()
    {
        $param['ids'] = $this->param('ids/a', '');

        validate({$validate.class_name}Validate::class)->scene('dele')->check($param);

        $data = {$service.class_name}Service::dele($param['ids']);

        return success($data);
    }
}
